package task;
import java.util.Scanner;
public class TaskSecond {
    public static void main(String[] args) {
        Scanner scanner  = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        scanner.close();
        System.out.println(countMagic(a,b));
    }

    public static int countMagic(int a, int b) {
        int count = 0;
        for (int i = a; i <= b; i++) {
            if (isMagicNumber(i)) {
                count++;
            }
        }
        return count;
    }

    private static boolean isMagicNumber(int number) {
        String numStr = Integer.toString(number);
        for (int i = 0; i < numStr.length(); i++) {
            for (int j = 0; j < numStr.length(); j++) {
                if (i != j) {
                    int digit1 = numStr.charAt(i) - '0';
                    int digit2 = numStr.charAt(j) - '0';
                    int twoDigitNumber = digit1 * 10+ digit2;
                    if (twoDigitNumber > 10 && isPrime((twoDigitNumber))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private static boolean isPrime(int number) {
        if (number <= 1) {
            return false;
        }
        for (int i = 2; i < Math.sqrt(number); i++) {
            if (number % i  ==0) {
                return false;
            }
        }
        return true;
    }
}
